home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / SpeakFreely / src / lpc10 / channel.c < prev    next >
C/C++ Source or Header  |  2000-05-18  |  3KB  |  118 lines

  1. /************************************************************************
  2. *
  3. *    CHANL Version 49
  4. *
  5. ************************************************************************
  6. *
  7. * CHANWR:
  8. *   Place quantized parameters into bitstream
  9. *
  10. *   Inputs:
  11. *    ORDER  - Number of reflection coefficients (not really variable)
  12. *    IPITV  - Quantized pitch/voicing parameter
  13. *    IRMS   - Quantized energy parameter
  14. *    IRC    - Quantized reflection coefficients
  15. *   Output:
  16. *    IBITS  - Serial bitstream
  17. *
  18. * CHANRD:
  19. *   Reconstruct parameters from bitstream
  20. *
  21. *   Inputs:
  22. *    ORDER  - Number of reflection coefficients (not really variable)
  23. *    IBITS  - Serial bitstream
  24. *   Outputs:
  25. *    IPITV  - Quantized pitch/voicing parameter
  26. *    IRMS   - Quantized energy parameter
  27. *    IRC    - Quantized reflection coefficients
  28. *
  29. *   IBITS is 54 bits of LPC data ordered as follows:
  30. *    R1-0, R2-0, R3-0,  P-0,  A-0,
  31. *    R1-1, R2-1, R3-1,  P-1,  A-1,
  32. *    R1-2, R4-0, R3-2,  A-2,  P-2, R4-1,
  33. *    R1-3, R2-2, R3-3, R4-2,  A-3,
  34. *    R1-4, R2-3, R3-4, R4-3,  A-4,
  35. *     P-3, R2-4, R7-0, R8-0,  P-4, R4-4,
  36. *    R5-0, R6-0, R7-1,R10-0, R8-1,
  37. *    R5-1, R6-1, R7-2, R9-0,  P-5,
  38. *    R5-2, R6-2,R10-1, R8-2,  P-6, R9-1,
  39. *    R5-3, R6-3, R7-3, R9-2, R8-3, SYNC
  40. */
  41.  
  42. #include "lpcdefs.h"
  43.  
  44. int bit[10] = {
  45.  2, 4, 8, 8, 8, 8, 16, 16, 16, 16 
  46. };
  47.  
  48. int iblist[53] = {
  49. 13, 12, 11, 1, 2, 13, 12, 11, 1, 2, 13, 10,
  50. 11, 2, 1, 10, 13, 12, 11, 10, 2, 13, 12, 11,
  51. 10, 2, 1, 12, 7, 6, 1, 10, 9, 8, 7, 4,
  52. 6, 9, 8, 7, 5, 1, 9, 8, 4, 6, 1, 5,
  53. 9, 8, 7, 5, 6 
  54. };
  55.  
  56. channel(which, ipitv, irms, irc, ibits )
  57. int which, *ipitv, *irms, irc[ORDER], ibits[54];
  58. {
  59. int i;
  60. static int isync;
  61. int itab[13];
  62.  
  63. switch(which) {
  64. case 0: /*chanwr*/
  65. /************************************************************************
  66. *    Place quantized parameters into bitstream
  67. ************************************************************************
  68.  
  69. *   Place parameters into ITAB    */
  70.  
  71. itab[0] = *ipitv;
  72. itab[1] = *irms;
  73. itab[2] = 0;
  74. for(i=1;i<=ORDER;i++)
  75.     itab[i+2] = irc[ORDER+1-i] & 32767 ;
  76.  
  77. /*   Put 54 bits into IBITS array    */
  78.  
  79. for(i=1;i<=53;i++)    {
  80.     ibits[i] = itab[iblist[i-1]-1] & 1;
  81.     itab[iblist[i-1]-1] = itab[iblist[i-1]-1] >> 1;
  82. }
  83. ibits[54] = isync&1;
  84. isync = 1 - isync;
  85.  
  86. break;
  87.  
  88. /************************************************************************
  89. *    Reconstruct parameters from bitstream
  90. *************************************************************************/
  91. case 1: /*chanwr*/
  92.  
  93. /*   Reconstruct ITAB    */
  94.  
  95. for(i=0;i<13;i++)
  96.     itab[i] = 0;
  97.  
  98. for(i=1;i<=53;i++)
  99.     itab[iblist[53-i]-1] = itab[iblist[53-i]-1]*2 + ibits[54-i];
  100.  
  101.  
  102. /*   Sign extend RC's    */
  103.  
  104. for(i=1;i<=ORDER;i++)
  105.     if( (itab[i+2] & bit[i-1])  != 0 ) itab[i+2] -= 2*bit[i-1];
  106.  
  107. /*   Restore variables    */
  108.  
  109. *ipitv = itab[0];
  110. *irms = itab[1];
  111. for(i=1;i<=ORDER;i++)
  112.     irc[i] = itab[ORDER+3-i];
  113.  
  114. break;
  115. }
  116.  
  117. }
  118.